package com.madou.yy.football;

import javax.swing.*;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;

public class InfoPanel extends JPanel implements Runnable{

    Color bgColor1 = new Color(203, 120, 0);
    Color bgColor2 = new Color(255, 156, 0);

    Color textColor = new Color(138, 81, 0);

    Thread thread = new Thread(this);
    int time=0;
    int score =0;
    int count=0;

    public InfoPanel(){
        thread.start();
    }

    public void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        g.setColor(bgColor1);
        g.fillRect(0,0,getWidth(),getHeight());
        g.setColor(bgColor2);
        g.fillRect(0,8,getWidth(),getHeight()-8);
        Font font = new Font("阿里巴巴普惠体 Medium",1,32);
        g.setFont(font);
        g2d.setColor(Color.BLACK);
        g2d.drawString("分数",30,45);
        g2d.drawString("TIME",250,45);
        g2d.drawString("次数",540,45);
        g2d.setColor(textColor);
        g2d.fillRoundRect(100,20,80,30,25,25);
        g2d.fillRoundRect(335,20,120,30,25,25);
        g2d.fillRoundRect(620,20,80,30,25,25);
        g2d.setColor(Color.WHITE);
        g2d.drawString(String.format("%02d",score),120,47);
        g2d.drawString(String.format("%02d:%02d",time/60,time%60),345,47);
        g2d.drawString(String.format("%02d",count),638,47);
    }

    public void addScore(int star) {
        this.score++;
        this.score+=star;
    }

    public void addCount() {
        this.count++;
    }

    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(1000);
                time++;
            } catch (InterruptedException e) {
               e.printStackTrace();
            }
            repaint();
        }
    }
}
